<template>
  <div class="app-container">
    <el-tabs type="border-card" @tab-click="handleClick">
      <el-tab-pane label="广告">
        <div class="filter-container">
          <el-input
            v-model="listQuery.name"
            placeholder="机构名称"
            style="width: 100px;"
            class="filter-item"
            @keyup.enter.native="handleFilter"
          />
          <el-select
            v-model="listQuery.button"
            clearable
            placeholder="状态"
            style="width: 150px;"
            class="filter-item"
          >
            <!-- <el-option label="全部">全部</el-option> -->
            <el-option :value="1" label="开启">开启</el-option>
            <el-option :value="0" label="全部">全部</el-option>
          </el-select>
          <el-button
            v-waves
            class="filter-item"
            type="primary"
            icon="el-icon-search"
            @click="handleFilter"
          >
            搜索
          </el-button>
        </div>
        <el-table
          :key="tableKey"
          v-loading="listLoading"
          :data="tableData"
          border
          fit
          highlight-current-row
          style="width: 100%;"
        >
          <el-table-column label="机构名称" min-width="110" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.accountName }}</span>
            </template>
          </el-table-column>
           <el-table-column label="计划名称" min-width="110" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.plan_name }}</span>
            </template>
          </el-table-column>
          <el-table-column label="开始时间" min-width="150" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.startTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="结束时间" min-width="80" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.endTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="投放预算数量" min-width="80" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.exposureBudget   }}</span>
            </template>
          </el-table-column>
          <el-table-column label="进件成功数" min-width="80" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.successNum }}</span>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="listQuery.current"
          :limit.sync="listQuery.size"
          @pagination="statisticalSep"
        />
      </el-tab-pane>
      <el-tab-pane label="保险">
        <div class="filter-container">
          <el-input
            v-model="listQuery1.name"
            placeholder="机构名称"
            style="width: 100px;"
            class="filter-item"
            @keyup.enter.native="handleFilter"
          />
          <el-select
            v-model="listQuery1.button"
            clearable
            placeholder="状态"
            style="width: 150px;"
            class="filter-item"
          >
            <!-- <el-option label="全部">全部</el-option> -->
            <el-option :value="1" label="开启">开启</el-option>
            <el-option :value="0" label="全部">全部</el-option>
          </el-select>
          <el-button
            v-waves
            class="filter-item"
            type="primary"
            icon="el-icon-search"
            @click="handleFilter"
          >
            搜索
          </el-button>
        </div>
        <el-table
          :key="tableKey"
          v-loading="listLoading"
          :data="tableData"
          border
          fit
          highlight-current-row
          style="width: 100%;"
        >
          <el-table-column label="机构名称" min-width="110" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.accountName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="计划名称" min-width="110" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.plan_name }}</span>
            </template>
          </el-table-column>
          <el-table-column label="开始时间" min-width="150" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.startTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="结束时间" min-width="90" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.endTime }}</span>
            </template>
          </el-table-column>
           <el-table-column label="投放预算数量" min-width="80" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.exposureBudget   }}</span>
            </template>
          </el-table-column>
          <el-table-column label="进件成功数" min-width="90" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.successNum }}</span>
            </template>
          </el-table-column>
           <el-table-column label="进件失败数" min-width="90" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.failNum }}</span>
            </template>
          </el-table-column>
          <el-table-column label="进件成功率" min-width="90" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.successRate }}%</span>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="listQuery1.current"
          :limit.sync="listQuery1.size"
          @pagination="statisticalSep1"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getsumInto,} from "@/api/advertising";
import waves from "@/directive/waves"; // waves directive
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
export default {
  name: "CountChannel",
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableData: [],
      dayData: [],
      total: 0,
      daytotal: 0,
      tableKey: 0,
      listQuery: {
        name:"",
        type:1,
        current:1,
        size:10,
        button:0
      },
      listQuery1:{
        name:"",
        type:2,
        current:1,
        size:10,
        button:0
      },
      times: [],
      dayId: 0,
      countChannelUsersNum: 0,
      countUvNum: 0,
      daydialogFormVisible: false,
      dialogPvVisible: false,
      optionsCopy: [],
      options: [],
      tabActive: "0",
      listLoading: false,
      total:0
    };
  },
  created() {
    this.statisticalSep();
  },
  methods: {
    handleClick(tab) {
      this.tabActive = tab.index;
      this.handleFilter();
    },

    // 获取列表
    async statisticalSep() {
      const res = await getsumInto(this.listQuery);
      this.tableData = res.data.data.records;
      this.total=res.data.data.total
    },
    async statisticalSep1() {
      const res = await getsumInto(this.listQuery1);
      this.tableData = res.data.data.records;
      this.total=res.data.data.total
    },
    // 搜索
    handleFilter() {
      if (this.tabActive == "0") {
        this.statisticalSep(this.listQuery);
      } else if (this.tabActive == "1") {
        this.statisticalSep1(this.listQuery1);
      }
    },
  }
};
</script>

<style scoped>
.cap {
  opacity: 0.5;
}
</style>
